Skip to main content

Human Access Module

Human Access API

API for granting and tracking developer SSH access to virtual machines (VMs) via Ansible.


POST /workspace/access/human (Not for Dev/Local Usage)

Initiates SSH access to a developer by injecting their SSH key into the specified VM using an Ansible playbook.

Request Body

{
"userEmail": "developer@example.com",
"userSshKey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...",
"vmId": "vm-abc123"
}
FieldTypeDescriptionRequired
userEmailstringDeveloper's email address
userSshKeystringDeveloper's SSH public key
vmIdstringIdentifier of the target VM

Responses

  • 202 Accepted
{
"operationId": "12345678-1234-1234-1234-123456789012"
}
  • 400 Bad Request: Invalid payload
  • 404 Not Found: VM not found
  • 500 Internal Server Error: Access request failed

GET /workspace/access/human/status/:operationId (Not for Dev/Local Usage)

Returns the status of the access operation.

Path Parameter

NameTypeDescription
operationIdstringUUID of the access request

Response (200 OK)

{
"status": "running",
"logs": [
"[2025-06-02T10:00:00Z] Operation initiated",
"[2025-06-02T10:00:01Z] Processing SSH access request for VM vm-abc123"
],
"vm": {
"vmId": "vm-abc123",
"ipAddress": "192.168.1.10",
"status": "running"
}
}
FieldTypeDescription
statusstringStatus of operation (pending, running, success, error)
logsstring[]Log messages for the operation
errorstringError message if operation failed (optional)
vmobjectVM info if access succeeded (optional)

Behavior

  • The operation is asynchronous:

    • SSH key and email are recorded in the DB immediately
    • Ansible is triggered in the background
  • Progress is tracked via GET /status/:operationId


Internals

  • Ansible Playbook: ./ansible/workspace/human-access.yml
  • Dynamic Inventory: Generated per run
  • Vars File Format:
host_ip: <VM IP>
new_developer_key: <user's SSH key>
old_developer_key: <existing SSH key>
  • Ansible Path Constants:
export const ansibleHumanAccessPaths = {
grantAccess: {
playbook: './ansible/workspace/human-access.yml',
inventory: './ansible/workspace/environment/hosts.yml',
vars: './ansible/workspace/vars/vars.yml'
}
};

Ansible Playbook Workflow

roles/human-access/tasks/main.yml

  • Debugs SSH key vars

  • Ensures .ssh directory exists for both ubuntu and root

  • Reads and filters authorized_keys:

    • Removes the old SSH key
    • Adds the new SSH key
  • Writes the final authorized_keys file to both ubuntu and root